<?php
class User 
{
	private $_id;
	private $_login;
	private $_pass;
	private $_supend;
	private $_email;
	private $_name;
	private $_prenom;
	private $_type;
	
	public function __construct(){
		$this->_id = 0;
		$this->_login = "";
		$this->_pass = "";
		$this->_supend = 0;
		$this->_email= "";
		$this->_name = "";
		$this->_prenom = "";
		$this->_type = 3;
	}
	public function getId(){
		return $this->_id;
	}
	
	public function getLogin(){
		return $this->_login;
	}
	
	public function getPass(){
		return $this->_pass;
	}
	
	public function getSuspend(){
		return $this->_supend;
	}
	
	public function getEmail() {
		return $this->_email;	
	}
	
	public function getName(){
		return $this->_name;
	}
	
	public function getPrenom(){
		return $this->_prenom;
	}
	
	public function getType(){
		if($this->_type == 1){
			return "ADMIN";
		}elseif($this->_type == 2){
			return "REDAC";
		}else {
			return "USER";
		}
	}
	
	public function setId($id){
		$this->_id = $id;
	}
	
	public function setLogin($log){
		$this->_login = $log;
	}
	
	public function setPass($pass){
		$this->_pass = $pass;
	}
	
	public function setSuspend(){
		$this->_supend = !$this->_supend;
	}
	
	public function setEmail($email) {
		$this->_email = $email;
	}
	
	public function setName($name){
		$this->_name = $name;
	}
	
	public function setPrenom($pre){
		$this->_prenom = $pre;
	}
	
	public function setType($type){
		if($type == "ADMIN"){
			$this->_type = 1;
		}elseif($type == "REDAC"){
			$this->_type = 2;
		}elseif($type == "USER"){
			$this->_type = 3;
		}
	}
	
	public function update(){
		$link = DB_connect();
		$req =  "UPDATE user_blog " +
				"SET login = '"+ $this->_id + "', password = '" + $this->_pass + "', "+
				"email = '" + $this->_email + "', name = '" + $this->_name + "', " +
				"prenom = '" + $this->_prenom + "', type = '" + $this->_prenom + "', "+
				"suspend  '" + $this->_supend +"' WHERE `ID`= '" + $this->_id + "'";
		return DB_execSQL($req, $link);
	}
	
	public function create(){
		$req = "INSERT INTO user_blog (ID, login, password, email, name, prenom, type, suspend) " +
			   "VALUES ('"+ $this->_id + "','" + $this->_login + "','" + md5($this->_pass) + "','" + 
			   $this->_email + "','" + $this->_name + "','" + $this->_prenom + "','" + $this->_type 
			   + "','" + $this->_supend +"')";
		return DB_execSQL($req, $link);
	}
} 
?>